package xyz.yeidi.utils;

import xyz.yeidi.pojo.User;
import xyz.yeidi.service.api.UserService;
import xyz.yeidi.service.impl.UserServiceImpl;

/**
 * @Author JIP
 * @Date 2021-08-04 10:13
 * @Version 1.0
 * @Describe :  用于加密的Utils
 */
public class EncryptionUtils {
    private static final Integer PUBLICKEY = 6;
    private static final Integer LEFT = 0;
    private static final Integer RIGHT = 1;

    public static String encryption(String pwd){
        StringBuilder sb = new StringBuilder();
        char[] chars = pwd.toCharArray();
        swap(chars,LEFT,RIGHT);
        for(char c:chars){
            sb.append((char) (c^PUBLICKEY));
        }
        return sb.toString();
    }

    public static String decode(String pwd){
        return encryption(pwd);
    }

    public static void swap(char [] chars,int l,int r){
        char temp = chars[l];
        chars[l] = chars[r];
        chars[r] = temp;
    }
}
